1. Field of the Invention
The present invention relates to techniques for allocating memory within a computer system. More specifically, the present invention relates to a method and an apparatus for redirecting external memory allocation operations to an internal memory manager in order to better control the allocation of memory within a computing device.
2. Related Art
The rapid growth of the Internet, coupled with the increasing availability of wireless data networks, has led to an explosion in the number of Internet-connected devices. Virtually all devices that contain microprocessors are being connected to the Internet, including cell phones, PDAs, and personal communicators (cell phone/PDA hybrids). These devices are typically small in size to facilitate portability, which results in limited resources. Most devices in this category are memory-constrained, and hence contain limited storage space.
Due to the memory-constrained nature of these devices, effective memory management, including garbage collection, is critical to their operation. However, creating virtual machines for these memory-constrained devices that facilitate effective memory management is a challenging task.
When programming on top of existing “external” system layers that allocate memory, the programmer has no control over external memory management. In this case, memory fragmentation is highly likely, which can lead to memory exhaustion and the premature termination of executing programs due to lack of memory.
To remedy this problem, it is possible for a programmer to allocate data structures in a garbage-collected heap. This allows a compacting garbage collector to be used to reduce memory fragmentation. For data structures that cannot be easily allocated on the garbage-collected heap, a programmer can avoid making calls to an external memory manager, and can instead call internal memory allocation code, which can be tuned to avoid memory fragmentation.
Unfortunately, the above-described techniques but cannot be used in all situations. For example, memory that is allocated by external libraries is outside of the control of the application. Consequently, the programmer is not able to either allocate this memory on the garbage-collected heap or to use internal memory allocation code.
What is needed is a method and an apparatus for efficiently managing memory that is allocated externally without the problems listed above.